package com.zc.study.thread.多线程第五章节.thread_4_1_5;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class Run {
    private static Timer timer = new Timer();
    public static class MethodA extends TimerTask{

        @Override
        public void run() {
            System.out.println("A运行了"+new Date().toLocaleString());
            this.cancel();
        }
    }
    public static class MethodB extends TimerTask{

        @Override
        public void run() {
            System.out.println("B运行了"+new Date().toLocaleString());
        }
    }

    public static void main(String[] args) {
        try {
            MethodA a = new MethodA();
            MethodB b = new MethodB();
            SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
            String dateString = "2018-3-14 15:11:00";
            Date date = sdf.parse(dateString);
            timer.schedule(a,date,4000);
            timer.schedule(b,date,4000);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
